package com.ropa.java.sba;

import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableAsync
@Slf4j
@RestController
public class SpringBootAsyncApp {
    static ApplicationContext applicationContext;
    public static void main(String[] args) {
        applicationContext = SpringApplication.run(SpringBootAsyncApp.class, args);
    }


    @Async
    @EventListener(DemoEvent.class)
    public void listener(){
        log.info("in listener");
        //
        ThreadUtil.sleep(1500);
    }


    @RequestMapping("pub")
    public void pub(){
        applicationContext.publishEvent(new DemoEvent());
    }


    static class DemoEvent{

    }


}
